package com.horsen.service.base.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * knife4j 配置类
 *
 * @author Horsen
 */
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {
    /**
     * 前台网站
     *
     * @return Docket实例
     */
    @Bean("webApi")
    public Docket webApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(webApiInfo())
                .groupName("webApi")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.horsen.service"))
                .paths(PathSelectors.regex("/web/.*"))
                .build();
    }

    /**
     * 后台管理系统
     *
     * @return Docket实例
     */
    @Bean("adminApi")
    public Docket adminApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(adminApiInfo())
                .groupName("adminApi")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.horsen.service"))
                .paths(PathSelectors.regex("/admin/.*"))
                .build();
    }

    /**
     * 前台网站ApiInfo
     *
     * @return ApiInfo实例
     */
    private ApiInfo webApiInfo() {
        return new ApiInfoBuilder()
                .title("HSEDU_前台网站API文档")
                .description("Horsen的毕业设计")
                .contact(new Contact("Horsen", "http://horsenliu.gitee.io", "horsenliu@qq.com"))
                .version("0.1")
                .build();
    }

    /**
     * 后天管理系统ApiInfo
     *
     * @return ApiInfo实例
     */
    private ApiInfo adminApiInfo() {
        return new ApiInfoBuilder()
                .title("HSEDU_后台管理系统API文档")
                .description("Horsen的毕业设计")
                .contact(new Contact("Horsen", "http://horsenliu.gitee.io", "horsenliu@qq.com"))
                .version("0.1")
                .build();
    }
}
